Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add old, new, diff and operation to WebhookCause #857

Merged
merged 1 commit into from
Nov 17, 2021

Conversation

sambhav
Copy link
Contributor

@sambhav sambhav commented Oct 31, 2021

Adding kwargs old, new, diff and operation to the WebhookCause and
passing them to the appropriate handler. This allows users to write
more powerful webhooks and allows them to create validation and
mutation webhooks that can look at the old object to determine
their behavior. This commit also adds the operation field to the
passed kwargs to allow users to create more powerful/flexibly webhooks.

closes: #851

Comment on lines 129 to 130
old = bodies.BodyEssence(old_body) if old_body is not None else None
new = bodies.BodyEssence(new_body) if new_body is not None else None
Copy link
Owner

@nolar nolar Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. Generally, looks great and the feature might be useful.

The only concern is here, in these lines. The body essence is different from the body — the essence removes all the garbage. The definition of "garbage" is flexible, but mostly it is the system metadata: e.g. generation/resourceVersion/timestamps. I'm not sure how Kubernetes passes the metadata in admission hooks — I simply didn't pay attention to it before. So, I will perform some experiments locally to see how it fits and feels before merging.

As a side-note (no action is needed; for my own remembering later): In the change-detecting handlers, the essence also removes the status stanza and re-adds the explicitly monitored fields. But that was done for the purpose of not (over-)reacting to non-essential changes, i.e. to dummy/technical events or other controllers storing their status fields (or even annotations of other Kopf-based controllers). In the case of admission, the reaction happens anyway, so there is no big win in removing the status/annotations. It can actually be more confusing if a change is admitted, but the diff is empty — so, it should not be made empty. [/the end of the side-note]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you prefer this to be the body or the body essence? I am good with either.

@nolar
Copy link
Owner

nolar commented Nov 1, 2021

PS: The massive unit-test failure is probably caused by 3rd-party changes in async_timeout — I will take a look at this later. It is not related to this PR.

DeprecationWarning: with timeout() is deprecated, use async with timeout() instead

@nolar
Copy link
Owner

nolar commented Nov 2, 2021

Please rebase on main and force-push — #859 has fixed the tests.

@sambhav
Copy link
Contributor Author

sambhav commented Nov 2, 2021

@nolar done :)

@sambhav sambhav force-pushed the webhook-cause branch 2 times, most recently from c8c24fd to 9abdb2c Compare November 4, 2021 23:21
Adding kwargs old, new, diff and operation to the WebhookCause and
passing them to the appropriate handler. This allows users to write
more powerful webhooks and allows them to create validation and
mutation webhooks that can be look at the old object to determine
their behavior. This commit also adds the operation field to the
passed kwargs to allow users to create more powerful/flexibly wenhooks.

Signed-off-by: Sambhav Kothari <sambhavs.email@gmail.com>
@sambhav
Copy link
Contributor Author

sambhav commented Nov 4, 2021

@nolar updated it to use bodies.Body instead. That should also fix the CI mypy issue.

@sambhav sambhav requested a review from nolar November 4, 2021 23:23
@sambhav
Copy link
Contributor Author

sambhav commented Nov 16, 2021

@nolar just a ping in case this PR slipped through your inbox :)

@nolar
Copy link
Owner

nolar commented Nov 17, 2021

@samj1912 Sorry for the delay. Don't worry, I didn't forget it — just working hard on another issue (which finally works!).

@nolar nolar merged commit 408686a into nolar:main Nov 17, 2021
@sambhav sambhav deleted the webhook-cause branch November 17, 2021 21:52
@nolar
Copy link
Owner

nolar commented Nov 17, 2021

Released as 1.35.3

@sambhav
Copy link
Contributor Author

sambhav commented Nov 17, 2021

Amazing! Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow using old and new for admission controllers
2 participants